package com.geovis.emergency.spd.biz.pc.service.impl;


import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.geovis.emergency.spd.biz.pc.mapper.PcPlanResponseMapper;
import com.geovis.emergency.spd.biz.pc.service.IPcPlanResponseService;
import com.geovis.emergency.spd.entity.pc.entity.PcPlanResponse;
import com.geovis.emergency.spd.entity.pc.pojo.vo.PcPlanResponseRecommendVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 应急预案指挥模块 -  响应预案 服务实现类
 * </p>
 *
 * @author Lonsho
 * @since 2022-06-17
*/

@Service
@RequiredArgsConstructor
@Slf4j
public class PcPlanResponseServiceImpl extends ServiceImpl<PcPlanResponseMapper, PcPlanResponse> implements IPcPlanResponseService {
    public LambdaQueryWrapper<PcPlanResponse> getRecommend(PcPlanResponseRecommendVO queryDTO) {
        //创建查询条件
        LambdaQueryWrapper<PcPlanResponse> wrapper = Wrappers.lambdaQuery(PcPlanResponse.class).orderByDesc(PcPlanResponse::getCreateTime);
        if (ObjectUtil.isNotEmpty(queryDTO)) {
            wrapper.inSql(ObjectUtil.isNotEmpty(queryDTO.getType()),PcPlanResponse::getPcPlanId,"SELECT id FROM pc_plan WHERE type='"+queryDTO.getType()+"' and data_status = '1'")
                    .eq(ObjectUtil.isNotEmpty(queryDTO.getGroupId()), PcPlanResponse::getGroupId, queryDTO.getGroupId())
                    .eq(ObjectUtil.isNotEmpty(queryDTO.getLevel()), PcPlanResponse::getLevel, queryDTO.getLevel());
        }
        return wrapper;
    }
}
